<template>
	<view class="container">
		<view class="user">
			<view class="user__info">
				<view class="name">{{orderInfo.address_info.realname}}</view>
				<view class="mobile">{{orderInfo.address_info.mobile}}</view>
			</view>
			<view class="user__address">{{orderInfo.address_info.address}}</view>
		</view>
		<view class="goods">
			<view class="item" v-for="(item,index) in orderInfo.has_many_order_goods" :key="index">
				<image :src="item.thumb"></image>
				<view class="item__info">
					<view class="title">{{item.title}}</view>
					<view class="amount">
						<view class="price">￥{{item.goods_price}}</view>
						<view class="num">×{{item.total}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="order-info">
			<view class="item">
				<view class="item__title">订单编号</view>
				<text>{{orderInfo.order_sn}}</text>
			</view>
			<view class="item">
				<view class="item__title">交易状态</view>
				<text>{{orderInfo.status_name}}</text>
			</view>
			<view class="item">
				<view class="item__title">支付方式</view>
				<text>{{orderInfo.pay_type_name}}</text>
			</view>
		</view>
		<view class="total">
			<view class="total__goods">
				<view class="title">商品小计</view>
				<text>{{orderInfo.pay_type_name}}</text>
			</view>
			<view class="total__amount">实付费：<span>￥{{orderInfo.price}}</span></view>
		</view>
		<view class="btn" v-if="orderInfo.status != 1">
			<view class="item" :class="(i.value == 1 || i.value == 5) ? 'item--green' : ''"
				v-for="(i, idx) in orderInfo['button_models']" :key="idx" @click.stop="handleOrderBtn(orderInfo, i)">
				{{i.name}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId: '',
				orderInfo: {}
			};
		},
		onLoad(options) {
			console.log(options);
			if (options.order_id) {
				this.orderId = options.order_id
				this.init()
			}
		},
		onShow() {

		},
		methods: {
			// 初始化
			init() {
				this.getOrderList();
			},
			// 获取订单列表
			getOrderList() {
				let url = '/addons/yun_shop/api.php?&route=order.detail'
				let params = {
					order_id: this.orderId
				}
				this.$api.get(url, params).then(res => {
					this.orderInfo = res.data
				})
			},

			// 点击订单相关按钮
			handleOrderBtn(item, btnItem) {
				if (btnItem.value == 8) {
					this.$u.toast(`${btnItem.name}！`);
				} else if (btnItem.value == 41) {
					this.$u.toast(`${btnItem.name}!`);
				} else {
					let url = `/addons/yun_shop/api.php?route=${btnItem.api}`
					let params = {
						order_id: item.id
					}
					uni.showModal({
						title: '提示',
						content: `确认要${btnItem.name}吗？`,
						success: res => {
							if (res.confirm) {
								this.$api.get(url, params).then(res => {
									this.$u.toast(`${btnItem.name}成功！`);
								})
							}
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	@import './order-detail.scss'
</style>
